package com.lordjoe.collectiveintelligence;

/**
 * com.lordjoe.collectiveintelligence.DistanceCalculator
 *
 * @author Steve Lewis
 * @date May 11, 2009
 */
public class DistanceCalculator
{
    public static DistanceCalculator[] EMPTY_ARRAY = {};
    public static Class THIS_CLASS = DistanceCalculator.class;


    /**
     * Description -
     * see
     *  http://edndoc.esri.com/arcobjects/9.0/Samples/Geometry/Great_Circle_Distance.htm
     * @param lat1 - Latitude of origin point in decimal degrees
     * @param lon1 - longitude of origin point in deceimal degrees
     * @param lat2 - latitude of destination point in decimal degrees
     * @param lon2 - longitude of destination point in decimal degrees
     * @return metricDistance - great circle distance in meters
     */
    public static double distance(double lat1, double lon1, double lat2, double lon2)
    {

        double radLat1 = Math.toRadians(lat1);
        double radLon1 = Math.toRadians(lon1);
        double radLat2 = Math.toRadians(lat2);
        double radLon2 = Math.toRadians(lon2);

        double d = Math.acos(
                (Math.cos(radLat1) * Math.cos(radLat2)) + (Math.sin(radLat1) * Math.sin(
                        radLat2)) * (Math.cos(radLon1 - radLon2)));
        return (d * EARTH_CIRC_METERS);
    }

    private static double EARTH_CIRC_METERS = 40030218; // Radius = 6371007 (GRS80)

}
